<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Usuarios extends CI_Controller {

	function __construct(){
		parent::__construct();
		$this->load->library('session');
	}
	
    public function index() {
        $this->load->view('cadastro_usuario');
    }
    
    function sair(){
    	$this->session->unset_userdata('id_usuario');
    	$this->session->unset_userdata('nome_usuario');
    	$this->session->sess_destroy();
    	$this->load->view('principal');
    }
    function entrar() {
    	$this->load->model('usuario_model');
    	
    	$dados = array(
	    	'login' => $this->input->post('login'),
	    	'senha' => $this->input->post('senha'),
    	);
    	$query = $this->usuario_model->entrar($dados);
    	if ($query->num_rows() == 1){
    		$linha = $query->row();
    		$this->session->set_userdata('nome_usuario',$linha->nome);
    		$this->session->set_userdata('id_usuario',$linha->id);
    		$this->load->view('principal');
    	}else{
    		$this->load->view('principal');	
    	}
    }
}